
import websocket
import json
import math

def handleFortyTwo(event):
    switcher = {
        "unknown": None,
        "0x49cf6f5d44e70224e2e23fdcdd2c053f30ada28b.feeds.activity.eventsCreated": handleEventCreated(event["payload"])
    }
    switcher.get(event["event"], lambda: None)()

def start():
    socket = websocket.WebSocketApp('wss://feeds.prod.blur.io/socket.io/?tabId=pKzRU7SRBQDn&storageId=n3kEOR5uxjEF&EIO=4&transport=websocket')

    def onopen():
        print('Connected to server')
        print('connected')
        socket.send('40')

    def onclose():
        print('Disconnected from server')
        start()

    def onmessage(data):
        event = json.loads(data)
        if event['code'] == 2:
            socket.send('3')
        elif event['code'] == 42:
            handlefortytwo(event)

    socket.onopen = onopen
    socket.onclose = onclose
    socket.onmessage = onmessage

    socket.run_forever()

start()